package com.study.cloud.gateway.common.rule;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Objects;

/**
 * 一个服务对应多个服务示例
 * @author wangwancheng
 * @create 2025/7/19 14:09
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ServiceInstance implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 服务实例id  ip:port
     */
    protected String serviceInstanceId;
    /**
     * 服务定义唯一Id
     */
    protected String uniqueId;
    /**
     * 服务实例ip
     */
    protected String ip;
    /**
     * 服务实例端口
     */
    protected Integer port;
    /**
     * 服务实例标签
     */
    protected String tags;
    /**
     * 服务实例权重
     */
    private int weight;
    /**
     * 服务注册 时间
     */
    private Long registerTime;
    /**
     * 服务实例版本
     */
    private String version;
    /**
     * 服务实例是否可用
     */
    protected Boolean enabled = true;
    /**
     * 服务实例是否灰度
     */
    private Boolean gray;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ServiceInstance that = (ServiceInstance) o;
        return Objects.equals(serviceInstanceId, that.serviceInstanceId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(serviceInstanceId);
    }
}
